<template>
  <div class="app-container table-app-container">
    <component :is="currentForm" v-if="currentForm !== 'DEFAULT'" :process-definition-id="processDefinitionId" :code="code" />
  </div>
</template>

<script>
import CKSQ from './forms/CKSQ.vue'
import CKFH from './forms/approve.vue'
import CKSP from './forms/approve.vue'
import CKQR from './forms/CKQR.vue'
// import DEFAULT from './forms/DEFAULT.vue'
import { startForm } from '@neu/dcam-ui/api/workflowDefinition'
import { currentNodes } from '@neu/dcam-ui/api/workflowInstance'
export default {
  name: 'OutboundProcess',
  components: {
    CKSQ,
    CKFH,
    CKSP,
    CKQR
  },
  data() {
    return {
      currentForm: 'DEFAULT',
      processDefinitionId: this.$route.params.processDefinitionId,
      code: this.$route.params.code ? this.$route.params.code : '',
      processInstanceId: this.$route.params.processInstanceId
    }
  },
  created() {
    /** 调用后台接口取到当前form的组件KEY,进行组件展现 */
    if (this.processInstanceId) {
      currentNodes(this.processInstanceId).then(res => {
        const data = res.data
        if (data.length > 0) {
          this.currentForm = data[0].formKey
        }
      })
    } else {
      startForm(this.processDefinitionId).then(res => {
        this.currentForm = res.data.formKey
      })
    }
  }
}
</script>
